package com.promise.jokerdream.task

import com.promise.jokerdream.task.base.NetworkStep
import com.promise.jokerdream.task.base.RequestContext
import com.promise.jokerdream.task.base.SerialTask
import com.promise.jokerdream.task.base.StepResult
import com.promise.jokerdream.task.base.TaskType

/**
 * 立即执行的任务
 */
class ImmediateTask(
    name: String,
    repeatCount: Int = 1,
    private val networkAction: suspend () -> Unit
) : SerialTask(name, TaskType.IMMEDIATE, repeatCount) {
    
    override fun getSteps(): List<NetworkStep> {
        return listOf(SimpleNetworkStep("immediate_action", networkAction))
    }
    
    override fun getRepeatInterval(): Long = TaskConfig.REPEAT_INTERVAL
}

/**
 * 简单的网络请求步骤
 */
class SimpleNetworkStep(
    override val stepName: String,
    private val networkAction: suspend () -> Unit
) : NetworkStep {
    
    override suspend fun execute(context: RequestContext): StepResult {
        return try {
            networkAction()
            StepResult.Success()
        } catch (e: Exception) {
            StepResult.Failure(e, "Network action failed: ${e.message}")
        }
    }
}
